package com.test.redislock;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @Author zz-lxf
 * @E-mail 629938044@qq.com
 * @Date 2021/12/13 15:27
 * @Version 1.0
 */
@Configuration
public class RedisConfiguration {

    /**
     * 去除redis序列化时，key-value的乱码问题
     * @param redisTemplate
     * @return
     */
    @Bean
    @Primary
    public RedisTemplate setRedisTemplate(RedisTemplate redisTemplate) {
        RedisSerializer stringSerializer = new StringRedisSerializer();
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(stringSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(stringSerializer);
        return redisTemplate;
    }
}
